#include "stdio.h"
#include "string.h"

#include <stdlib.h>


//#define WINDOWS

#ifdef WINDOWS


// Windows-specific wrappers for socket functions
#include "winsock.h"
#include "winsock2.h"

#define SockSend(sd, buf, len)			send(sd, buf, len, 0)
#define SockReceive(sd, buf, len)		recv(sd, buf, len, 0)
#define SockClose(sd)						closesocket(sd)
#define SockAddrType					struct sockaddr
#define SockError(msg)					MessageBox(0,msg,"Proxy server problem", MB_SYSTEMMODAL)
#define SockLastError()					 WSAGetLastError()
#define SockErrWouldBlock			  WSAEWOULDBLOCK
#define SockSleep()							Sleep(100L)

#define Strnicmp(s1, s2, n)					strnicmp(s1, s2, n)

#else

/* According to POSIX.1-2001 */
#include <sys/select.h>

/* According to earlier standards */
#include <sys/time.h>
#include <sys/types.h>
// Linux/Cygwin-specific wrappers for socket functions

#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>


typedef int SOCKET;
typedef unsigned int UINT;

#define INVALID_SOCKET  (SOCKET)(~0)
#define SOCKET_ERROR            (-1)

#define SockSend(sd, buf, len)			write(sd, buf, len)
#define SockReceive(sd, buf, len)		read(sd, buf, len)
#define SockClose(sd)						close(sd)
#define SockAddrType					struct sockaddr_in
//#define SockError(msg)					  fprintf(stderr, msg)
#define SockError(msg)					  printf(msg)
#define SockLastError()					 (errno)
#define SockErrWouldBlock			  EWOULDBLOCK
#define SockSleep()							usleep(200000)

#define Strnicmp(s1, s2, n)					strncasecmp(s1, s2, n)

#endif		// platform-specific wrappers for socket functions


//
// EXPORTED DECLARATIONS
//

void proxy_start(char *ip, int listenPortparm, char *extproxyaddr, int extproxyport, int (*callback_fn)(), int comeback, int singlethread);
void proxy_newport(int newport);
